//
//  MineMessageListCell.m
//  ShowYork
//
//  Created by hxh on 2020/11/13.
//  Copyright © 2020 hxh. All rights reserved.
//

#import "MineMessageListCell.h"
#import "PaddingLabel.h"
@interface MineMessageListCell ()
@property (nonatomic,strong)UIImageView *iconImgView;
@property (nonatomic,strong)UILabel *titleLb;
@property (nonatomic,strong)UILabel *countLb;
@end

@implementation MineMessageListCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setUI];
    }
    return self;
}

- (void)setUI{
    
    
    self.iconImgView = [[UIImageView alloc]init];
    self.iconImgView.layer.cornerRadius = 20;
    self.iconImgView.layer.masksToBounds = YES;
    [self.contentView addSubview:self.iconImgView];
    [self.iconImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(16);
        make.top.equalTo(self.contentView).offset(20);
        make.bottom.equalTo(self.contentView).offset(-20);
        make.size.mas_equalTo(CGSizeMake(40, 40));
    }];
    
    self.titleLb = [[UILabel alloc]init];
    self.titleLb.text = @"赞";
    self.titleLb.textColor = C51;
    self.titleLb.font = font(14);
    [self.contentView addSubview:self.titleLb];
    [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.iconImgView);
        make.left.equalTo(self.iconImgView.mas_right).offset(16);
    }];
    self.countLb = [[UILabel alloc]init];
    self.countLb.layer.cornerRadius = 10;
    self.countLb.layer.masksToBounds = YES;
    self.countLb.textAlignment = NSTextAlignmentCenter;
    self.countLb.backgroundColor = RGBA(232, 85, 83, 1);
    self.countLb.text = @"9";
    self.countLb.textColor = [UIColor whiteColor];
    self.countLb.font = font(12);
    [self.contentView addSubview:self.countLb];
    [self.countLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.right.equalTo(self.contentView).offset(-16);
        make.width.mas_equalTo(20);
        make.height.mas_equalTo(20);
    }];
}
+(instancetype)cellWithTableView:(UITableView *)tableView{
    NSString *ID = @"MineMessageListCell";
    MineMessageListCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[MineMessageListCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.accessoryView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"mine_access_tag"]];
    }
    return cell;
}
- (void)setMessageTitle:(NSString *)messageTitle icon:(nonnull NSString *)icon bageValue:(nonnull NSString *)value{
    self.titleLb.text = messageTitle;
    CGFloat width = 20;
    if (value.intValue < 99 && value.intValue > 9){
        width = 30;
    }else if(value.intValue > 99 && value.intValue <= 999){
        width = 40;
    }else if(value.intValue > 999){
        width = 45;
    }
    
    if (value.intValue > 999) {
        self.countLb.text = @"999+";
    }else if (value.intValue == 0){
        self.countLb.text = @"";
        width = 0;
    }else{
        self.countLb.text = value;
    }
    [self.countLb mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(width);
    }];
    
    self.iconImgView.image = [UIImage imageNamed:icon];
    
}

@end
